import file from '@system.file';
import prompt from '@system.prompt';

export default {
    data: {
        isLogined: false,
        user: "",
        password:"",
        path: "",
        isFirstStart: false
    },
    onCreate() {
        console.info('TaobaoDemoApplication onCreate');
        file.access({
            uri: "internal://app/firstStart",
            fail: () => {
                this.isFirstStart = true;
                file.writeText({
                    uri: "internal://app/firstStart",
                    text: "2021190015",
                    fail: (data, code) => console.log(data, code)
                });
            }
       });
    },
    onDestroy() {
        console.info('TaobaoDemoApplication onDestroy');
    },
    isLoggedIn() {
        return this.isLogined;
    },
    getUser() {
        return this.user;
    },
    login(u, p) {
        if(u == null || p == null){
            prompt.showDialog({
                message: "请输入账号与密码",
            })
        }
        if (this.user === u && this.password === p) {
            console.log("Login success");
            this.isLogined = true;
            this.user = u;
            return true;
        }
        return false;
    },
    register(u, p) {
        this.user = u;
        this.password = p;
        console.log("New user: ", u, p);
    },
};
